package ferp.core.ai.filter;

import ferp.core.game.Game;
import ferp.core.player.Hand;

/**
 * User: igorgok
 * Date: 9/5/12 5:37 PM
 */
public class FilterMissingSuits
{
  // must be called only for first hand
  public static int apply(int candidates, int[] hands, int player, int hand)
  {
    // get the remaining cards in opponent hands as one big hand
    int oh = hands[Game.next(player)] | hands[Game.previous(player)];
    int result = 0;

/*
    for (Card.Suit s : Card.Suit.rising)
      if (Hand.only(oh, s) != 0)
        result |= Hand.only(candidates, s);
*/

    // this is to speed up execution
    if ((oh & 0x000000FF) != 0)
      result |= candidates & 0x000000FF;
    if ((oh & 0x0000FF00) != 0)
      result |= candidates & 0x0000FF00;
    if ((oh & 0x00FF0000) != 0)
      result |= candidates & 0x00FF0000;
    if ((oh & 0xFF000000) != 0)
      result |= candidates & 0xFF000000;

    // only if filtered hand has cards
    // when only missing suits left just peek one card, no matter which one
    return result == 0 ? Hand.first(candidates) : result;
  }
}
